package lg.minecraft.plugin.testeconomy;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author langle__
 * @version 1.0
 */
public class Placeholder extends PlaceholderExpansion {

    @Override
    public @NotNull String getAuthor() {
        return "langle__";
    }

    @Override
    public @NotNull String getVersion() {
        return "1.0.0";
    }

    @Override
    public @NotNull String getIdentifier() {
        return "TestEconomy";
    }

    @Override
    public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
        switch (params.toLowerCase()) {
            case "balance":
                return String.valueOf((int) getBalance(player.getName()));
            case "balance_double":
                return String.format("%.2f", getBalance(player.getName()));
            default:
                return null;
        }
    }

    private double getBalance(String playerName) {
        return TestEconomy.getStorage().getBalance(playerName);
    }

}
